package com.itany.corejava.code07_面向对象.bms;

/**
 * @author 石小俊
 * 2024年07月17日 13:34
 */
public class LoanSavingAccount extends SavingAccount implements Loanable {

    // 贷款金额
    private double loanAmount;

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    @Override
    public void providerLoan(double money) {
        // 由于没有贷款审批流程,此处不考虑审批,默认贷款一定成功
        // 当贷款成功之后,贷款总额发生变化
        // 贷款总额=原来的贷款金额+当前贷款的金额
        loanAmount += money;
    }

    @Override
    public boolean payLoan(double money) {
        // 对于贷款的储蓄账户,还款的金额不能超出当前账户余额
        if (getBalance() >= money) {
            // 还款后发生两个变化
            // 1.账户余额减少
            setBalance(getBalance() - money);
            // 2.贷款总额减少
            loanAmount -= money;
            return true;
        }
        return false;
    }

    @Override
    public double query() {
        return this.loanAmount;
    }
}
